import fs from 'fs';

fs.writeFile('./bbb.txt', 'hello world', {
    encoding: 'utf-8',
    flag: 'a+' // 使⽤追加模式
    }, (err) => {
    console.log('写⼊⽂件结果:', err);
    });

const writeStream = fs.createWriteStream('./ccc.txt',
    { flags: 'a' }); // 追加写⼊

writeStream.on('open', (fd) => {
    console.log('⽂件被打开', fd);
    });

writeStream.write('coderwhy');
writeStream.write('aaaa');
writeStream.write('bbbb', (err) => {
    console.log("写⼊完成:", err);
    });

writeStream.on('finish', () => {
    console.log('写⼊完成了');
    });

writeStream.on('close', () => {
    console.log('⽂件被关闭~');
    });

writeStream.end('哈哈哈哈');